package com.yanqu.road.server.cmd.drugstore;

import com.yanqu.road.pb.drugstore.DrugStoreProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.drugstore.DrugStoreModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_DRUG_STORE_USE_POWER_ITEM, desc = "使用体力道具")
public class DrugStorePowerAddItemCmd extends AbstractCommand {

    int count;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        DrugStoreProto.DrugStorePowerAddItemReqMsg reqMsg = DrugStoreProto.DrugStorePowerAddItemReqMsg.parseFrom(packet.getBytes());
        count = reqMsg.getCount();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        ret = player.getModule(DrugStoreModule.class).usePowerAddItem(count);

    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0) {
            DrugStoreProto.DrugStorePowerAddItemRespMsg.Builder respMsg = DrugStoreProto.DrugStorePowerAddItemRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_DRUG_STORE_USE_POWER_ITEM, respMsg);
        }
    }
}
